package com.xbn.xbnmall.product.web;

import com.xbn.xbnmall.product.entity.CategoryEntity;
import com.xbn.xbnmall.product.service.CategoryService;
import com.xbn.xbnmall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author XBN
 * @date 2020/7/31 14:24
 * @email 78742541@qq.com
 */
@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
       List<CategoryEntity> categoryEntities= categoryService.getLevel1Categorys();
       model.addAttribute("categorys",categoryEntities);
        return "index";
    }

    //TODO  此接口多次请求数据库查询数据，导致吞吐量极低

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<Long, List<Catelog2Vo>>  getCatalogJson() throws InterruptedException {
        /*
        * Map   K一级分类id       V该一级分类旗下的二级分类集合
        * */
        Map<Long, List<Catelog2Vo>> map= categoryService.getCatalogJson();

        return map;
    }
    @ResponseBody
    @GetMapping("/product/gatewayTest")
    public String  gatewayTest(){
     return "网关测试";
    }
}
